//
//  RefreshMgr.m
//  CarCare
//
//  Created by ileo on 15/4/29.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "RefreshMgr.h"
#import "NetCar.h"
#import "AIUserInfo.h"
#import "SystemHelper.h"

NSString * const REFRESH_CARLOCATION = @"REFRESH_CARLOCATION";
NSString * const REFRESH_MONEY = @"REFRESH_MONEY";
NSString * const REFRESH_REWARD = @"REFRESH_REWARD";
NSString * const REFRESH_VOLTAGE = @"REFRESH_VOLTAGE";
NSString * const REFRESH_DEVICESTATUS = @"REFRESH_DEVICESTATUS";
NSString * const REFRESH_CARSTATUS = @"REFRESH_CARSTATUS";
NSString * const REFRESH_CARCONDITION = @"REFRESH_CARCONDITION";
NSString * const REFRESH_ORDERNOREAD = @"REFRESH_ORDERNOREAD";

@implementation RefreshMgr

IMP_SINGLETON

- (instancetype)init
{
    self = [super init];
    if (self) {
        __weak __typeof(self) wself = self;
        self.refreshCarLocation = [RefreshCarLocation sharedInstance];
        self.refreshCarLocation.RefreshCallBack = ^(id JSON){
            [[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_CARLOCATION object:nil userInfo:JSON];
        };

        self.refreshMoney = [RefreshMoney sharedInstance];
        self.refreshMoney.RefreshCallBack = ^(id JSON){
            [[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_MONEY object:nil userInfo:JSON];
        };
        [self.refreshMoney startRefreshWithTimeInterval:0];
        
        self.refreshReward = [RefreshReward sharedInstance];
        self.refreshReward.RefreshCallBack = ^(id JSON){
            if (wself.refreshReward.newReward == 0) {
                [SYSTEMHELPER clearIconNum];
            }
            [[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_REWARD object:nil userInfo:JSON];
        };
        [self.refreshReward startRefreshWithTimeInterval:0];
        
        self.refreshVoltage = [RefreshVoltage sharedInstance];
        self.refreshVoltage.RefreshCallBack = ^(id JSON){
            [[NSNotificationCenter defaultCenter] postNotificationName:REFRESH_VOLTAGE object:nil userInfo:JSON];
        };

        self.refreshDeviceStatus = [RefreshDeviceStatus sharedInstance];
        self.refreshDeviceStatus.RefreshCallBack = ^(id JSON)
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:REFRESH_DEVICESTATUS object:nil userInfo:JSON];
        };
        [self.refreshDeviceStatus startRefreshWithTimeInterval:0];
        
        self.refreshCarStatus = [RefreshCarStatus sharedInstance];
        self.refreshCarStatus.RefreshCallBack = ^(id JSON){
            [[NSNotificationCenter defaultCenter]postNotificationName:REFRESH_CARSTATUS object:nil userInfo:JSON];
        };
        [self.refreshCarStatus startRefreshWithTimeInterval:0];
        
        self.refreshCarCondition = [RefreshCarCondition sharedInstance];
        self.refreshCarCondition.RefreshCallBack = ^(id JSON)
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:REFRESH_CARCONDITION object:nil userInfo:JSON];
        };
        [self.refreshCarCondition startRefreshWithTimeInterval:0];
        
        self.refreshOrderNoRead = [RefreshOrderNoRead sharedInstance];
        self.refreshOrderNoRead.RefreshCallBack = ^(id JSON)
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:REFRESH_ORDERNOREAD object:nil userInfo:JSON];
        };
        [self.refreshOrderNoRead startRefreshWithTimeInterval:0];
        
    }
    return self;
}

-(void)refresh{
    [self.refreshMoney startRefreshWithTimeInterval:0];
    [self.refreshReward startRefreshWithTimeInterval:0];
    [self.refreshDeviceStatus startRefreshWithTimeInterval:0];
    [self.refreshCarLocation startRefreshWithTimeInterval:0];
    [self.refreshVoltage startRefreshWithTimeInterval:0];
    [self.refreshCarStatus startRefreshWithTimeInterval:0];
    [self.refreshCarCondition startRefreshWithTimeInterval:0
    ];
    [self.refreshOrderNoRead startRefreshWithTimeInterval:0];
}

@end
